package com.vitabuybuy.tv.ui.mine.order.adapter

import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.adaptebinding.ImageAdapter
import com.vitabuybuy.tv.databinding.ItemPic2Binding
import com.vitabuybuy.tv.dto.OrderDetailDto
import com.library.common.base.BindRecycAdapter

class CommentPictureAdapter :
    BindRecycAdapter<ItemPic2Binding, OrderDetailDto.ItemListBean.VideoAndPicBean>() {
    override fun onBindViewHolder(
        mBinding: ItemPic2Binding,
        itemData: OrderDetailDto.ItemListBean.VideoAndPicBean,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        if (itemData.tag == "video") {
            mBinding.ivPlay.visibility = View.VISIBLE
            ImageAdapter.setNomalImageUrl(
                mBinding.iv,
                itemData.cover,
                ContextCompat.getDrawable(mContext, R.drawable.default_image)
            )
        } else {
            mBinding.ivPlay.visibility = View.GONE
            ImageAdapter.setNomalImageUrl(
                mBinding.iv,
                itemData.fileUrl,
                ContextCompat.getDrawable(mContext, R.drawable.default_image)
            )
        }
        mBinding.ivDelete.setOnClickListener {
            if (lisetener != null)
                lisetener?.invoke(position)
        }
    }

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_pic_2
    }

    var lisetener: ((position: Int) -> Unit)? = null

    fun setOnClickDeleteListener(lisetener: ((position: Int) -> Unit)) {
        this.lisetener = lisetener
    }
}
